Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quick-lru

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quick-lru

Simple “Least Recently Used” (LRU) cache

  • 5.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.9M
decreased by-54.48%
Maintainers
1
Weekly downloads
 
Created

What is quick-lru?

The quick-lru package is a fast and efficient least-recently-used (LRU) cache implementation in JavaScript. It is designed to store a limited amount of items and evict the least-recently-used items once the limit is reached. This package is useful for caching results, reducing the number of expensive operations (like I/O), and improving application performance.

What are quick-lru's main functionalities?

Set and Get Items

This feature allows you to set and retrieve items from the cache using the 'set' and 'get' methods. The 'maxSize' option specifies the maximum number of items the cache can hold.

{"const QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 1000});
lru.set('key', 'value');
const value = lru.get('key'); // 'value'"}

Cache Eviction

This feature automatically evicts the least-recently-used items when the cache reaches its maximum size. In this example, after adding three items to a cache with a maxSize of 2, the first item is evicted.

{"const QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 2});
lru.set('a', 1);
lru.set('b', 2);
lru.set('c', 3);
// At this point, 'a' is evicted because it is the least recently used item"}

Cache Deletion and Clearing

This feature allows you to delete individual items or clear the entire cache. The 'delete' method removes a specific item, and the 'clear' method removes all items.

{"const QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 1000});
lru.set('key', 'value');
lru.delete('key'); // Removes 'key' from the cache
lru.clear(); // Removes all items from the cache"}

Cache Size and Existence Check

This feature provides methods to check the current size of the cache and whether a specific key exists in the cache. The 'size' property gives the number of items in the cache, and the 'has' method checks for the existence of a key.

{"const QuickLRU = require('quick-lru');
const lru = new QuickLRU({maxSize: 1000});
lru.set('key', 'value');
const size = lru.size; // 1
const hasKey = lru.has('key'); // true"}

Other packages similar to quick-lru

Keywords

FAQs

Package last updated on 01 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc